﻿
@{
    ViewData["Title"] = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div id="divForm" style="margin:2px;padding:2px;">
    <el-form :model="form" label-width="120px">
        <el-row :gutter="24">
            <el-col :span="12">
                <el-form-item label="分类名称" required>
                    <el-input v-model="form.categoryName" placeholder="在此处输入分类名称"></el-input>
                </el-form-item>
            </el-col>
        </el-row> 
        <el-row :gutter="24">
            <el-col :span="12">
                <el-form-item label="状态">
                    <el-radio-group v-model="form.enabled">
                        <el-radio :label='true'>启用</el-radio>
                        <el-radio :label='false'>禁用</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-col>
        </el-row> 
        <el-row :gutter="24">
            <el-col :span="12">
                <el-form-item label="排序号" required>
                    <el-input v-model="form.orderIndex" type="number"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-form-item>
            <el-button type="primary" @@click="SaveNewsCategory()" size="mini" v-show="pageButtons.includes('savenewscategory')">保存</el-button>
            <el-button @@click="Back()" size="mini">返回</el-button>
        </el-form-item>
    </el-form> 
</div> 
<script>

    var vueNewsCategory = new Vue({
        el: '#divForm',
        data() {
            return {
                pageButtons: [], 

                form: {
                    id: parseInt(getQueryString("id")||0),
                    categoryName: "", 
                    enabled:true,
                    orderIndex:0
                }
            }
        },
        created() {
            var _this = this; 

            _this.GetNewsCategory(); 

            _this.$getMenuButtons();
        },
        methods: {  
            GetNewsCategory() {
                var _this = this;
                _this.$get("@Url.Action("GetNewsCategory", "NewsCategory")?CategoryId="+_this.form.id ).then((res) => {
                    _this.form = res;
                    _this.defaultcheckedkeys = _this.form.parentId;
                });
            },
            SaveNewsCategory() {
                var _this = this;
                _this.form.orderIndex = parseInt(_this.form.orderIndex || 0); 
                _this.$post("@Url.Action("SaveNewsCategory", "NewsCategory")", _this.form).then((res) => {
                    _this.$success(res.message, function () {
                        _this.$back(true);
                    });
                });
            },
            Back() {
                this.$back();
            }
        }
    });
</script>

